package com.itheima.manager;

import cn.hutool.core.collection.CollectionUtil;
import com.itheima.domain.db.UserInfo;
import com.itheima.domain.mongo.UserLocation;
import com.itheima.domain.vo.MyMapMessageVo;
import com.itheima.service.db.UserInfoService;
import com.itheima.service.mongo.MapNeedMessageService;
import com.itheima.service.mongo.UserLocationService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.*;

@Component
public class ShowMapManager {

    @Reference
    private UserInfoService userInfoService;
    @Reference
    private MapNeedMessageService mapNeedMessageService;

    /**
     * 查询所有的用户返回到地图上
     *
     * @return
     */

    public List<MyMapMessageVo> findAllUserOnMap() {
//            获取mongo中的全部信息
        List<UserLocation> allLocationMessage = mapNeedMessageService.findLocationMessage();
        System.out.println("77787787878787878");
        ArrayList<MyMapMessageVo> myMapMessageVos = new ArrayList<>();
        if (CollectionUtil.isNotEmpty(allLocationMessage)) {
            for (UserLocation userLocation : allLocationMessage) {
                MyMapMessageVo myMapMessageVo = new MyMapMessageVo();
//          封装数据
                //        通过mysql获取全部用户信息
                UserInfo userInfo = userInfoService.findById(userLocation.getUserId().longValue());

            }
        }
        return myMapMessageVos;
    }


    @Reference
    private UserLocationService userLocationService;
    public Map findPeopleOnMap(Long userId) {
        UserInfo userInfo = userInfoService.findById(userId);
        Map map = userLocationService.findAddress(userId);
        map.put("nickName", userInfo.getNickname());
        map.put("avatar", userInfo.getAvatar());

        Iterator iterator = map.entrySet().iterator();
        while (iterator.hasNext()) {
            Map.Entry entry = (Map.Entry) iterator.next();
            Object key = entry.getKey();
            Object value = entry.getValue();
            System.out.println("Key = " + key + ", Value = " + value);
        }

        return map;

    }
}
